//OrderDaoImpl.java
package com.ylaihui.dao.impl;

import com.ylaihui.dao.OrderDao;
import com.ylaihui.pojo.Book;
import com.ylaihui.pojo.Order;

import java.util.List;

/**
 * @author lisimmy www.ylaihui.com
 * @create 2021-08-03
 */
public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public int saveOrder(Order order) {
        String sql = "insert into t_order(`order_id`,`create_time`,`price`,`status`,`user_id`) values(?,?,?,?,?)";

        return update(sql, order.getOrderId(), order.getCreateTime(), order.getPrice(), order.getStatus(), order.getUserId());
    }

    @Override
    public List<Order> queryOrders() {
        String sql = "select `order_id` orderId,`create_time` createTime,`price` price,`status` status,`user_id` userId from t_order";
        return queryForList(Order.class, sql);
    }

    @Override
    public Order queryOrderByOrderId(String orderId) {
        String sql = "select `order_id` orderId,`create_time` createTime,`price` price,`status` status,`user_id` userId from t_order where order_id = ?";
        return queryForOne(Order.class, sql, orderId);
    }

    @Override
    public int changeOrderStatus(String orderId, Integer status) {
        String sql = "update t_order set `status` = ? where order_id = ?";

        return update(sql, status, orderId);
    }

    @Override
    public List<Order> queryOrdersByUserId(Integer id) {
        String sql = "select `order_id` orderId,`create_time` createTime,`price` price,`status` status,`user_id` userId from t_order where user_id = ?";
        return queryForList(Order.class, sql, id);
    }

}
